<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

//get variables passed from add.php
$instructor_id = mysql_real_escape_string(strip_tags($_POST['iid']));
$q = "SELECT * FROM instructors WHERE id = '$instructor_id'";
$r = mysql_query($q);
$row = mysql_fetch_assoc($r);
$instructor_fname = $row['first_name'];
$instructor_lname = $row['last_name'];
$day_of_week = mysql_real_escape_string(strip_tags($_POST['dow']));
$starttime = mysql_real_escape_string(strip_tags($_POST['start']));
$endtime = mysql_real_escape_string(strip_tags($_POST['end']));

if (isset($_POST['mon']))
{
	$mon = $_POST['mon'];
}
else
{
	$mon = 0;
}

if (isset($_POST['tues']))
{
	$tues = $_POST['tues'];
}
else
{
	$tues = 0;
}

if (isset($_POST['weds']))
{
	$weds = $_POST['weds'];
}
else
{
	$weds = 0;
}

if (isset($_POST['thurs']))
{
	$thurs = $_POST['thurs'];
}
else
{
	$thurs = 0;
}

if (isset($_POST['fri']))
{
	$fri = $_POST['fri'];
}
else
{
	$fri = 0;
}

if (isset($_POST['sat']))
{
	$sat = $_POST['sat'];
}
else
{
	$sat = 0;
}

if (isset($_POST['sun']))
{
	$sun = $_POST['sun'];
}
else
{
	$sun = 0;
}

echo "<h1>Add Timeslot in ".stripslashes($instructor_fname)." ".stripslashes($instructor_lname)."</h1>";

$query = "INSERT INTO instructor_availability (id, instructor_id, day_id, start_time, end_time)
VALUES
('','$instructor_id','$day_of_week','$starttime','$endtime')";

$result = mysql_query($query);

if ($result)
{
	echo "Timeslot has been successfully added!";
	echo "<br />";
}
else
{
	echo "Timeslot was NOT able to be added at this time!";
	echo "<br />";
}

//close
mysql_close();

echo "<p>";
	echo "<a href='update_availability.php?id=$instructor_id'>&lt;&lt; Back to Instructors Portal</a><br />";
echo "</p>";

?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>